﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.Composition;
using WaterRevenueMS.Core.Repository.BasicSet;
using WaterRevenueMS.Componnent.Entities.BasicSet;
using WaterRevenueMS.Domain.ViewModels.BasicSet.KindOfWaterUse;
using WaterRevenueMS.Componnent.Common;

namespace WaterRevenueMS.Core.Service.BasicSet.Impl
{
    [Export(typeof(IKindOfWaterUseService))]
    public class KindOfWaterUseService : CoreServiceBase, IKindOfWaterUseService
    {
        [Import]
        public IKindOfWaterUseRepository KindOfWaterUseRepository { get; set; }

        public IQueryable<KindOfWaterUse> KindOfWaterUses
        {
            get { return KindOfWaterUseRepository.Entities; }
        }

        public OperationResult Insert(KindOfWaterUseModel model)
        {
            var entity = new KindOfWaterUse
            {
                Yong_SXZ=model.Yong_SXZ,
                CreateDT = DateTime.Now,
                ReviseDT = DateTime.Now,
                OrderNo=model.OrderNo,
                Jie_TSZ=model.Jie_TSZ,
                Yong_SL=model.Yong_SL,
                Yong_SDJ=model.Yong_SDJ,
                Yong_SLA=model.Yong_SLA,
                Yong_SDJA=model.Yong_SDJA,
                Yong_SLB=model.Yong_SLB,
                Yong_SDJB=model.Yong_SDJB,
                Yong_SLC=model.Yong_SLC,
                Yong_SDJC=model.Yong_SDJC
            };
            KindOfWaterUseRepository.Insert(entity);
            return new OperationResult(OperationResultType.Success, "添加成功");
        }

        public OperationResult Update(KindOfWaterUseModel model)
        {
            var entity = new KindOfWaterUse
            {
                Id=model.Id,
                ReviseDT = DateTime.Now,
                OrderNo = model.OrderNo,
                Yong_SXZ=model.Yong_SXZ,
                Jie_TSZ = model.Jie_TSZ,
                Yong_SL = model.Yong_SL,
                Yong_SDJ = model.Yong_SDJ,
                Yong_SLA = model.Yong_SLA,
                Yong_SDJA = model.Yong_SDJA,
                Yong_SLB = model.Yong_SLB,
                Yong_SDJB = model.Yong_SDJB,
                Yong_SLC = model.Yong_SLC,
                Yong_SDJC = model.Yong_SDJC
            };
            KindOfWaterUseRepository.Update(entity);
            return new OperationResult(OperationResultType.Success, "更新成功");
        }

        public OperationResult Delete(int Id)
        {
            var entity = KindOfWaterUseRepository.Entities.FirstOrDefault(t => t.Id == Id);
            if (entity != null)
            {
                KindOfWaterUseRepository.Delete(entity);
            }
            return new OperationResult(OperationResultType.Success, "删除成功");
        }
    }
}
